import requests
import execjs
import urllib.parse

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
}
with open('sgrsj.js', 'r', encoding='utf-8') as f:
    js_code = f.read()
    js_compile = execjs.compile(js_code)
timestamp = js_compile.call('encrypt_data', '2024-08-01T15:34:07')
timestamp_params = {
    'timestamp': timestamp,
}
response_timestamp = requests.get(f'https://api.weibotop.cn/getclosesttime?{urllib.parse.urlencode(timestamp_params)}',
                                  headers=headers)
timeid = js_compile.call('encrypt_data', response_timestamp.json()[0])
params = {
    'timeid': timeid,
}
response = requests.get(f'https://api.weibotop.cn/currentitems?{urllib.parse.urlencode(params)}', headers=headers)
decrypt_data = js_compile.call('decrypt_data', response.text)
print(decrypt_data)
